package com.penghaisoft.microwms.product.web.controller.insidewarehouse;

import javax.annotation.Resource;
import javax.ws.rs.core.MediaType;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.penghaisoft.microwms.common.Constant;
import com.penghaisoft.microwms.common.controller.BaseController;
import com.penghaisoft.microwms.common.dto.MesProductTypeDto;
import com.penghaisoft.microwms.common.dto.TransResult;
import com.penghaisoft.microwms.common.page.MesProductTypePager;
import com.penghaisoft.microwms.common.page.Pager;
import com.penghaisoft.microwms.common.service.IMesInterfaceService;
import com.penghaisoft.microwms.common.service.MesProperties;

/**
 * @ClassName: MesProductTypeController
 * @Description: 成品型号 获取
 * @author luoteng
 * @date 2018年11月2日 下午4:49:36
 */
@RestController
@RequestMapping(value = "/productType")
@Slf4j
public class MesProductTypeController extends BaseController {

	@Autowired
	private IMesInterfaceService mesInterfaceService;

	@Resource
	private MesProperties mesProperties;

	/**
	 * 查询列表
	 * 
	 * @param pager
	 * @return
	 */
	@PostMapping("list")
	public TransResult list(
			@RequestParam(name = "page", defaultValue = "1") int page,
			@RequestParam(name = "rows", defaultValue = "10") int rows,
			MesProductTypeDto mesProductTypeDto) {
		// 可用标识 1可用，0不可用
		mesProductTypeDto.setMarkAble("1");
		mesProductTypeDto.setPageNo(page - 1);
		mesProductTypeDto.setPageSize(rows);

		String url = mesProperties.getUrl()
				+ "/imes-provider/basicdata/product/model/query";

		TransResult result = mesInterfaceService.publicTransResult(url,
				MediaType.APPLICATION_JSON_TYPE,
				JSONObject.toJSONString(mesProductTypeDto));

		Pager<MesProductTypeDto> rtnPager = new Pager<MesProductTypeDto>();
		rtnPager.setPage(page);
		rtnPager.setRows(rows);

		if (result.getCode().equals(Constant.SUCCESS)) {
			MesProductTypePager pager = (MesProductTypePager)result.getData();
			rtnPager.setRecords(pager.getList());
			rtnPager.setTotalCount(pager.getTotalCount());
		}

		return success(rtnPager);
	}

}
